<%@ page language="java" isErrorPage="true" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
	<title>Server Error</title>
	
	<link rel="stylesheet" href="/requisiteworks/styles/normalize.css" />
	<link rel="stylesheet" href="/requisiteworks/styles/main.css" />
	
	
	<script type="text/javascript" src="/requisiteworks/scripts/raze.js" ></script>
	<script type="text/javascript" src="/requisiteworks/scripts/jsool-all.js" ></script>

	<style>
		body{
			margin:20px;
		}
		h1{
			font-size:20px;
			font-weight: bold;
			margin-bottom:10px;
		}
		strong{
			font-weight: bold;
			color: #330000 !important;
		}
	</style>

	<script type="text/javascript">

	jsool.onReady(function(){
		var panel = jsool.get("panel");
		var hidden = false;


		function toggle(){
			if(hidden){
				panel.applyStyle("display","block");
				hidden = false;
			}else{
				panel.applyStyle("display","none");
				hidden = true;
			}
		}

		jsool.get("toggle").on("click",toggle);
		toggle();
	});
	
	</script>

</head>
	<body>
		<h1>Ocorreu um erro no servidor</h1>
		
		<div class="erro">
		<%
			if(exception == null){
				exception = pageContext.getException();
				exception = (Exception)request.getAttribute("exception");
			}
		
			if(exception == null){
				exception = (Exception)request.getAttribute("exception");
			}
			if(exception!=null)
				out.print(exception.getMessage());

		%>
		</div>
		
		
		
		<br />
		<fieldset>
			<legend id="toggle" style="cursor:pointer;">Detalhes</legend>
			<div id="panel">
				<%
					if(exception != null){
						StackTraceElement[] elements = exception.getStackTrace();
						out.print("<strong>"+exception + "</strong><br />");
						for(int i = 0; i< elements.length; i++){
							out.print("&nbsp;&nbsp;&nbsp;&nbsp;");
							out.print(elements[i].toString().replace("\n","<br />") + "<br/>");
						}
						
						Throwable cause = exception.getCause();
						int maxDeph = 5, current = 0;
						
						while(cause != null && ((current++) < maxDeph)){
							out.print("<strong>"+cause + "</strong><br />");
							elements = cause.getStackTrace();
							cause = exception.getCause();							
							for(int i = 0; i< elements.length; i++){
								out.print("&nbsp;&nbsp;&nbsp;&nbsp;");
								out.print(elements[i].toString().replace("\n","<br />") + "<br/>");
							}
						}
					}
				%>
				
			</div>
		</fieldset>
	</body>
</html>